<%@page import="support.*, java.util.*, java.sql.*, java.lang.Integer" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Account</title>
</head>
<body>
    <%
    final int NULL = 0;
    final int INTEGER = 4;
    final int DOUBLE = 8;
    final int STRING = 12;
    
    RowSet applicantInfo = (RowSet) request.getAttribute("applicantInfo");
    RowSet rset = (RowSet) request.getAttribute("application");
    out.print("<h1>Hello " + applicantInfo.getString("username") + "!</h1>");
    out.println("Welcome to your <font color=\"blue\"><b> application page</b></font>");
    // checks if rset was properly set
    if(rset != null){

        // get number of columns
        ResultSetMetaData rsetMeta = rset.getMetaData();
        int numCol = rsetMeta.getColumnCount();

        // make table/columns
        out.print("<table border=\"1\">");
        
        // print column names/labels
        for (int i =0; i<numCol; i++){
            out.print("<td>" + rsetMeta.getColumnLabel(i+1) + "</td>");
        }

        // print applications
        while(rset.next()){
            out.print("<tr>");
            // loop through columns
            for(int i = 0; i < numCol; i++){
                out.print("<td>");
                // type checks how to handle tuple information
                switch(rsetMeta.getColumnType(i+1)){
                  case NULL:
                      out.print("None");
                      break;
                  case INTEGER:
                      out.print(rset.getInt(i+1));
                      break;
                  case DOUBLE:
                      out.print(rset.getDouble(i+1));
                      break;
                  case STRING:
                      // checks if string is null (Strings have optional fields)
                      if(rset.getString(i+1) == null)
                          out.print("None");
                      else
                          out.print(rset.getString(i+1));
                      break;
                  default:
                      if(rset.getString(i+1) == null)
                          out.print("None");
                      else
                          out.print(rset.getString(i+1));
                }
                out.print("</td>");
            }
            out.print("</tr>");
        }
        out.print("</table");
    }
    %>

</body>
</html>